
//碰撞盒矩形
class CCOLLISION_RECT extends CCOLLISION{

	//形状显示开关
	private shape_collision:boolean=false

	
	public constructor(ptr:CBASE,x:number,y:number,w:number,h:number,color?:number) {
		
		  super(ptr)
		  this.judgetype=judgetype.rectangle
		  this.shape=new egret.Shape();
		  this.setshape(x,y,w,h,color)
		 
		  this.parent.addChild(this.shape)
		  this.shapeCollisionSwitch=false
		  
		
	}
	public NormalVector():egret.Point[]//得到法向量
	{
		 var vectors=this.relpoint
		 var nomalvector:egret.Point[]=[]
		 for(let a=0;a<2;a++)
		  {
			let b=new egret.Point
		    b=vectors[a+1].subtract(vectors[a])

		    let long=Math.sqrt(b.x*b.x+b.y*b.y)
		     b.x/=long,b.y/=long
			
			 let c=new egret.Point
		      //得到法向量
		      c.x=-b.y,c.y=b.x
		     nomalvector.push(c)
		 }
		 return nomalvector
	}
	public set shapeCollisionSwitch(a:boolean) //是否开启形状碰撞提示
	{
		
		this.shape_collision=a
		if(a)
		{
			this.shape.touchEnabled=true;
			this.shape.alpha=0.5
		}
		else{
			this.shape.touchEnabled=false;
		    this.shape.alpha=0
		}
		
	}
	public get type():judgetype//得到type
	{
		return this.judgetype
	}
	public get relpoint():egret.Point[]//获得真实坐标
	{
		var vector:egret.Point[]=[]
		 for(let b=0;b<this.shapepoint.length;b++)
		  {
			  var local:egret.Point=new egret.Point
			   local.x=this.shapepoint[b].x+this.shape.x
		       local.y=this.shapepoint[b].y+this.shape.y
			   var anchoroff=new egret.Point(this.parent.anchorOffsetX,this.parent.anchorOffsetY)
			   var nowpoint= this.Pointrevolve(local,anchoroff,this.parent.rotation)
			   vector.push(new egret.Point(nowpoint.x+this.parent.x,nowpoint.y+this.parent.y))
		  }
	
		return vector
	}
	public get r():number
	{
		return 0
	}
	public setshape(x:number,y:number,w:number,h:number,color?:number)
	{
		  this.shape.graphics.clear();
		  this.shapepoint.splice(0,this.shapepoint.length)
		 
		   if(color==undefined)
		  this.shape.graphics.beginFill(0xff000,1);
		  else
          this.shape.graphics.beginFill(color,1);
		  this.shape.graphics.drawRect(-w/2,-h/2,w,h);

		  
		  this.shapepoint.push(new egret.Point(-w/2+x,-h/2+y),new egret.Point(w/2+x,-h/2+y),new egret.Point(w/2+x,h/2+y),new egret.Point(-w/2+x,h/2+y))
		  this.shape.graphics.endFill();
		
          this.shape.graphics.beginFill(0xfffff,1);
		  for(var a=0;a<this.shapepoint.length;a++)
		  {
			
			this.shape.graphics.drawCircle(this.shapepoint[a].x-x,this.shapepoint[a].y-y,5)
			
		  }
		  this.shape.x=x,this.shape.y=y;
		  this.shape.graphics.drawCircle(this.shape.anchorOffsetX,this.shape.anchorOffsetY,5)
		  this.shape.graphics.endFill();
		 
		 
	}

}